*---------------------------------------------------------------
*---------------------------------------------------------------
* This code base replicates SIGACTS results reported in 
* Tables 1, 2, A24, A25
*---------------------------------------------------------------
*---------------------------------------------------------------

clear all

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* To manually run file, set the working directory below *
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

cd "~/Dropbox/Historical Displacement and Ethnicity - Afghanistan/REPOSITORY"

*---------------------------------------------------------------
* Section 1: Load and define variables in SIGACTS analysis
*---------------------------------------------------------------

use "replication/data/input/SIGACTS.dta", clear

sort DISTID yw 

* displaced_pashton_percent = percent of villages designated as displaced Pashtuns
* distpop1213 = district population (in 1000s)
* CIVCAS_INS_pc = insurgent-initiated civilian casualties
* IED_FC_pc = IED find and clear missions
* IED_Threat_pc = IED tips
* DF_pc = direct fire engagements
* IDF_pc = indirect fire engagements
* IED_Explosion_pc = IED explosions
* Cache_FC_pc = Weapons cache find and clear missions
* Exploitation_pc = Intelligence gathering events
* Capture_pc = Insurgent captures
* threat2coin_pc = All tips about threats to counterinsurgent forces

*---------------------------------------------------------------
* Section 2: Make Table 1
*---------------------------------------------------------------

eststo clear

eststo: quietly reghdfe IED_Threat_pc L.c.CIVCAS_INS_pc L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe IED_Threat_pc L.c.CIVCAS_INS_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe threat2coin_pc L.c.CIVCAS_INS_pc L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe threat2coin_pc L.c.CIVCAS_INS_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 

	estadd local ss ""
	estadd local fe ""
	estadd local mstats "" 
	
esttab using "replication/results/tables/Table1.tex", style(tex) se nonotes keep(L.CIVCAS_INS_pc cL.CIVCAS_INS_pc#c.displaced_pashton_percent) /// 
	stats(ss ymean ysd fe distfe weekfe iedtrend df idf mstats N N_clust, labels("\hline \textsc{Summary Statistics}" "Outcome Mean" "Outcome SD" "\hline \textsc{Parameters}"  "District Fixed Effect" "Week Fixed Effect" "IED Detonation Trends" "Close Combat Trends" "Remote Combat Trends" "\hline \textsc{Model Statistics}" "N" "Clusters")) /// 
	nonumbers mtitles("\shortstack{ (1)\\ Baseline Model \\ IED Tips }" ///
	"\shortstack{(2) \\ Full Model \\ IED Tips}" "\shortstack{(3) \\ Baseline Model \\ Tactical tips}" ///
	"\shortstack{(4) \\ Full Model \\  Tactical tips}" ) ///
	varlabels(L.CIVCAS_INS_pc "Ins. CIVCAS, Lagged" cL.CIVCAS_INS_pc#c.displaced_pashton_percent "Ins. CIVCAS $\times$ Displaced Pashtuns") ///
	starlevels(* .10 ** .05 *** .01) replace

eststo clear

*---------------------------------------------------------------
* Section 3: Make Table 2
*---------------------------------------------------------------

eststo clear

eststo: quietly reghdfe IED_FC_pc L.c.IED_Threat_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe Cache_FC_pc L.c.IED_Threat_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe Exploitation_pc L.c.threat2coin_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe Capture_pc L.c.threat2coin_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 

	estadd local ss ""
	estadd local fe ""
	estadd local mstats "" 
	
esttab using "replication/results/tables/Table2.tex", style(tex) se nonotes keep(L.IED_Threat_pc cL.IED_Threat_pc#c.displaced_pashton_percent L.threat2coin_pc cL.threat2coin_pc#c.displaced_pashton_percent) /// 
	stats(ss ymean ysd fe distfe weekfe iedtrend df idf mstats N N_clust, labels("\hline \textsc{Summary Statistics}" "Outcome Mean" "Outcome SD" "\hline \textsc{Parameters}"  "District Fixed Effect" "Week Fixed Effect" "IED Detonation Trends" "Close Combat Trends" "Remote Combat Trends" "\hline \textsc{Model Statistics}" "N" "Clusters")) /// 
	nonumbers mtitles("\shortstack{ (1)\\ Baseline Model \\ Roadside Bombs \\ Found/Cleared }" ///
	"\shortstack{(2) \\ Baseline Model \\ Weapon Caches \\ Found/Cleared}" "\shortstack{(3) \\ Baseline Model \\ Tactical Safe \\ House Raids }" ///
	"\shortstack{(4) \\ Baseline Model \\ Insurgents Captured \\ and Detained}" ) ///
	varlabels(L.IED_Threat_pc "Tips about IED deployment, Lagged" L.threat2coin_pc "All Tactical Tips, Lagged" cL.IED_Threat_pc#c.displaced_pashton_percent "Tips about IED $\times$ Displaced Pashtuns" cL.threat2coin_pc#c.displaced_pashton_percent "All Tactical Tips $\times$ Displaced Pashtuns") ///
	starlevels(* .10 ** .05 *** .01) replace

eststo clear

*---------------------------------------------------------------
* Section 4: Make Table A24
*---------------------------------------------------------------

eststo clear

eststo: quietly reghdfe IED_Threat_pc L.c.CIVCAS_INS_pc L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe IED_Threat_pc L.c.CIVCAS_INS_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe threat2coin_pc L.c.CIVCAS_INS_pc L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe threat2coin_pc L.c.CIVCAS_INS_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 

	estadd local ss ""
	estadd local fe ""
	estadd local mstats "" 
	
esttab using "replication/results/tables/TableA24.tex", style(tex) se nonotes keep(L.CIVCAS_INS_pc cL.CIVCAS_INS_pc#c.displaced_pashton_percent  L.DF_pc L2.DF_pc L3.DF_pc L4.DF_pc  L.IDF_pc L2.IDF_pc L3.IDF_pc L4.IDF_pc L.IED_Explosion_pc L2.IED_Explosion_pc L3.IED_Explosion_pc L4.IED_Explosion_pc) order(L.CIVCAS_INS_pc cL.CIVCAS_INS_pc#c.displaced_pashton_percent) /// 
	stats(ss ymean ysd fe distfe weekfe iedtrend df idf mstats N N_clust, labels("\hline \textsc{Summary Statistics}" "Outcome Mean" "Outcome SD" "\hline \textsc{Parameters}"  "District Fixed Effect" "Week Fixed Effect" "IED Detonation Trends" "Close Combat Trends" "Remote Combat Trends" "\hline \textsc{Model Statistics}" "N" "Clusters")) /// 
	nonumbers mtitles("\shortstack{ (1)\\ Baseline Model \\ IED Tips }" ///
	"\shortstack{(2) \\ Full Model \\ IED Tips}" "\shortstack{(3) \\ Baseline Model \\ Tactical tips}" ///
	"\shortstack{(4) \\ Full Model \\  Tactical tips}" ) ///
	varlabels(L.CIVCAS_INS_pc "Ins. CIVCAS, Lagged" cL.CIVCAS_INS_pc#c.displaced_pashton_percent "Ins. CIVCAS $\times$ Displaced Pashtuns" L.DF_pc "DF (1 week lag)" L2.DF_pc "DF (2 week lag)" L3.DF_pc "DF (3 week lag)" L4.DF_pc  "DF (4 week lag)"  L.IDF_pc  "IDF (1 week lag)" L2.IDF_pc  "IDF (2 week lag)" L3.IDF_pc  "IDF (3 week lag)" L4.IDF_pc "IDF (4 week lag)" L.IED_Explosion_pc  "IED (1 week lag)" L2.IED_Explosion_pc "IED (2 week lag)" L3.IED_Explosion_pc "IED (3 week lag)" L4.IED_Explosion_pc "IED (4 week lag)") ///
	starlevels(* .10 ** .05 *** .01) replace

eststo clear

*---------------------------------------------------------------
* Section 5: Make Table A25
*---------------------------------------------------------------

eststo clear

eststo: quietly reghdfe IED_FC_pc L.c.IED_Threat_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe Cache_FC_pc L.c.IED_Threat_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe Exploitation_pc L.c.threat2coin_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 
eststo: quietly reghdfe Capture_pc L.c.threat2coin_pc##c.displaced_pashton_percent L(1/4).DF_pc L(1/4).IDF_pc L(1/4).IED_Explosion_pc if year>=2006&year<=2014 [aweight=distpop1213], absorb(DISTID yw) vce(cluster DISTID)
	estadd ysumm
	estadd local distfe 				"Yes" 
	estadd local weekfe 				"Yes" 
	estadd local iedtrend 				"Yes" 
	estadd local df 					"Yes" 
	estadd local idf 					"Yes" 

	estadd local ss ""
	estadd local fe ""
	estadd local mstats "" 
	
esttab using "replication/results/tables/TableA25.tex", style(tex) se nonotes keep(L.IED_Threat_pc cL.IED_Threat_pc#c.displaced_pashton_percent L.threat2coin_pc cL.threat2coin_pc#c.displaced_pashton_percent L.DF_pc L2.DF_pc L3.DF_pc L4.DF_pc  L.IDF_pc L2.IDF_pc L3.IDF_pc L4.IDF_pc L.IED_Explosion_pc L2.IED_Explosion_pc L3.IED_Explosion_pc L4.IED_Explosion_pc ) order(L.IED_Threat_pc cL.IED_Threat_pc#c.displaced_pashton_percent L.threat2coin_pc cL.threat2coin_pc#c.displaced_pashton_percent) /// 
	stats(ss ymean ysd fe distfe weekfe iedtrend df idf mstats N N_clust, labels("\hline \textsc{Summary Statistics}" "Outcome Mean" "Outcome SD" "\hline \textsc{Parameters}"  "District Fixed Effect" "Week Fixed Effect" "IED Detonation Trends" "Close Combat Trends" "Remote Combat Trends" "\hline \textsc{Model Statistics}" "N" "Clusters")) /// 
	nonumbers mtitles("\shortstack{ (1)\\ Baseline Model \\ Roadside Bombs \\ Found/Cleared }" ///
	"\shortstack{(2) \\ Baseline Model \\ Weapon Caches \\ Found/Cleared}" "\shortstack{(3) \\ Baseline Model \\ Tactical Safe \\ House Raids }" ///
	"\shortstack{(4) \\ Baseline Model \\ Insurgents Captured \\ and Detained}" ) ///
	varlabels(L.IED_Threat_pc "Tips about IED deployment, Lagged" L.threat2coin_pc "All Tactical Tips, Lagged" cL.IED_Threat_pc#c.displaced_pashton_percent "Tips about IED $\times$ Displaced Pashtuns" cL.threat2coin_pc#c.displaced_pashton_percent "All Tactical Tips $\times$ Displaced Pashtuns" L.DF_pc "DF (1 week lag)" L2.DF_pc "DF (2 week lag)" L3.DF_pc "DF (3 week lag)" L4.DF_pc  "DF (4 week lag)"  L.IDF_pc  "IDF (1 week lag)" L2.IDF_pc  "IDF (2 week lag)" L3.IDF_pc  "IDF (3 week lag)" L4.IDF_pc "IDF (4 week lag)" L.IED_Explosion_pc  "IED (1 week lag)" L2.IED_Explosion_pc "IED (2 week lag)" L3.IED_Explosion_pc "IED (3 week lag)" L4.IED_Explosion_pc "IED (4 week lag)") ///
	starlevels(* .10 ** .05 *** .01) replace

eststo clear
